home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_01 / allison / copy2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-02  |  420 b   |  22 lines

  1. LISTING 5 - A Function that copies a file via block I/O
  2.  
  3. /* copy2.c */
  4. #include <stdio.h>
  5.  
  6. int copy(FILE *dest, FILE *source)
  7. {
  8.     size_t count;
  9.     static char buf[BUFSIZ];
  10.  
  11.     while (!feof(source))
  12.     {
  13.         count = fread(buf,1,BUFSIZ,source);
  14.         if (ferror(source))
  15.             return EOF;
  16.         if (fwrite(buf,1,count,dest) != count)
  17.             return EOF;
  18.     }
  19.     return 0;
  20. }
  21.  
  22.